import 'package:flutter/material.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';

//回票信息
class TicketInfo extends StatefulWidget {
  @override
  _TicketInfoState createState() => _TicketInfoState();
}

class _TicketInfoState extends State<TicketInfo> {
  bool invoiceInfoShow = false; //显示隐藏回票信息
  Map<String, dynamic> deliveryInfo = {
    "deliveryTime": "2020-11-27 11:21",
    "deliveryType": "韵达",
    "deliveryNumber": "2020154654546546665"
  }; //发货信息

  @override
  Widget build(BuildContext context) {
    return Container(
      color: Colors.white,
      margin: EdgeInsets.only(top: setWidth(15)),
      padding: EdgeInsets.only(
          left: setWidth(15), top: setWidth(18), right: setWidth(15)),
      child: Column(
        children: [
          Container(
            margin: EdgeInsets.only(bottom: setWidth(10)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                  child: Text(
                    "开票信息",
                    style: TextStyle(
                        color: Color(0xff323232),
                        fontSize: setSp(16),
                        fontWeight: FontWeight.w600),
                  ),
                ),
                GestureDetector(
                  behavior: HitTestBehavior.opaque,
                  onTap: () {
                    setState(() {
                      invoiceInfoShow = !invoiceInfoShow;
                    });
                  },
                  child: Container(
                    padding: EdgeInsets.all(10),
                    child: SizedBox(
                      width: setWidth(12),
                      height: setWidth(6),
                      child: Image.asset(
                        invoiceInfoShow
                            ? "assets/images/shouqi.png"
                            : "assets/images/zhankai.png",
                        width: setWidth(12),
                        height: setWidth(6),
                        fit: BoxFit.cover,
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ),
          Container(
            child:
                invoiceInfoShow ? _backInvoice() : _deliveryItem(deliveryInfo),
          ),
        ],
      ),
    );
  }

  //回票信息
  Widget _backInvoice() {
    return Column(
      children: [
        invoiceInfo("开票金额:", "34792.00（含税）", richText: "工时费"),
        invoiceInfo("发票抬头:", "太平洋保险股份有限公司安徽合肥分公司"),
        invoiceInfo("税号:", "983798oqiuwqu2323"),
        copyInfo("地址:", "安徽省合肥市"),
        copyInfo("邮寄地址:", "某某某 12545689756 安徽省合肥市庐阳区万科中心2154"),
        SizedBox(
          height: setWidth(50),
        ),
        _deliveryItem(deliveryInfo)
      ],
    );
  }

  //发票信息
  Widget invoiceInfo(String title, String content, {String richText = ""}) {
    return Container(
      margin: EdgeInsets.only(bottom: setWidth(18)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            width: setWidth(64),
            child: Text(
              title,
              style: TextStyle(color: Color(0xff323232), fontSize: setSp(14)),
            ),
          ),
          Expanded(
            child: Row(
              children: [
                Container(
                  child: Text(content,
                      style: TextStyle(
                          color: Color(0xff323232), fontSize: setSp(14))),
                ),
                Container(
                  child: Text(richText,
                      style: TextStyle(
                          color: Color(0xffFF6701), fontSize: setSp(14))),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  //发票邮寄信息
  Widget _deliveryItem(Map<String, dynamic> deliveryInfo) {
    return Container(
      margin: EdgeInsets.only(bottom: setWidth(20)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          //回票信息
          Container(
            margin: EdgeInsets.only(bottom: setWidth(18)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  width: setWidth(70),
                  child: Text(
                    "回票信息:",
                    style: TextStyle(
                        color: Color(0xff323232), fontSize: setSp(15)),
                  ),
                ),
                Expanded(
                  child: Container(
                    child: Text(deliveryInfo["deliveryTime"] as String,
                        style: TextStyle(
                            color: Color(0xff323232), fontSize: setSp(15))),
                  ),
                ),
              ],
            ),
          ),
          //快递方式
          Container(
            margin: EdgeInsets.only(bottom: setWidth(18)),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  width: setWidth(70),
                  child: Text(
                    "快递方式:",
                    style: TextStyle(
                        color: Color(0xff323232), fontSize: setSp(15)),
                  ),
                ),
                Expanded(
                  child: Container(
                    child: Text(deliveryInfo["deliveryType"] as String,
                        style: TextStyle(
                            color: Color(0xff323232), fontSize: setSp(15))),
                  ),
                ),
              ],
            ),
          ),
          //快递单号
          Container(
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.center,
              children: [
                Container(
                  width: setWidth(70),
                  alignment: Alignment.centerLeft,
                  child: Text(
                    "快递单号:",
                    style: TextStyle(
                        color: Color(0xff323232), fontSize: setSp(15)),
                  ),
                ),
                Expanded(
                  child: Container(
                    child: Text(deliveryInfo["deliveryNumber"] as String,
                        style: TextStyle(
                            color: Color(0xff323232), fontSize: setSp(15))),
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  //拷貝发票信息
  Widget copyInfo(String title, String content) {
    return Container(
      margin: EdgeInsets.only(bottom: setWidth(18)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Container(
            width: setWidth(70),
            child: Text(
              title,
              style: TextStyle(color: Color(0xff323232), fontSize: setSp(15)),
            ),
          ),
          Expanded(
            child: Container(
              child: Text(content,
                  style:
                      TextStyle(color: Color(0xff323232), fontSize: setSp(15))),
            ),
          ),
          SizedBox(
            width: setWidth(31),
          ),
          GestureDetector(
            onTap: () {
              copy(content);
            },
            child: Container(
              child: Text(
                "复制",
                style: TextStyle(color: Color(0xff1666F1), fontSize: setSp(15)),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
